package com.liao.kv.key;

import com.liao.kv.base.BaseDimension;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class ComDimension extends BaseDimension {

    //时间维度
    private DateDimension dateDimension = new DateDimension();
    //联系人维度
    private ContactDimension contactDimension = new ContactDimension();

    public ComDimension() {
        super();
    }

    public ComDimension(DateDimension dateDimension, ContactDimension contactDimension) {
        super();
        this.dateDimension = dateDimension;
        this.contactDimension = contactDimension;
    }

    public DateDimension getDateDimension() {
        return dateDimension;
    }

    public void setDateDimension(DateDimension dateDimension) {
        this.dateDimension = dateDimension;
    }

    public ContactDimension getContactDimension() {
        return contactDimension;
    }

    public void setContactDimension(ContactDimension contactDimension) {
        this.contactDimension = contactDimension;
    }

    public int compareTo(BaseDimension o) {
        ComDimension other=(ComDimension) o;
        //先比较联系人维度
        int result=contactDimension.compareTo(other.contactDimension);
        if(result==0){
            //再比较日期维度
            result=dateDimension.compareTo(other.dateDimension);
        }
        return result;
    }

    public void write(DataOutput out) throws IOException {
        //调用自己写的类输出
        this.contactDimension.write(out);
        this.dateDimension.write(out);
    }

    public void readFields(DataInput in) throws IOException {
        this.contactDimension.readFields(in);
        this.dateDimension.readFields(in);
    }
}
